Breakpoint Injection

I created a Unity window tool that allows easy injection of breakpoint templates directly into the Rider IDE. This streamlines the debugging process by automating breakpoint setup, saving time during development.

My Code

Breakpoint Class

This is the container where i store all the info about the breakpoint

Breakpoint Class


public class Breakpoint
{
    public int id;
    public Object file;
    public string path = "\path\to\file";
    public int lineNumber = 0;
    [Tooltip("Name of the method that the code line is in")]
    public string method;
    public string code;
    public bool isConditional = false;
    public string condition;

    public Tuple range;

    public void FindMethod()
    {
        var fileContent = File.ReadAllText(path);
        var lineCode = GetLine(fileContent, lineNumber);
        code = StripTabs(lineCode);
        range = Getrange(fileContent, code);
    }

    private string GetLine(string script, int targetLine)
    {
        var lines = script.Split('\n');
        return lines[targetLine];
    }

    private Tuple Getrange(string script, string lineContent)
    {
        var startrange = script.IndexOf(lineContent);
        var lines = LinesCount(script, startrange);
        startrange -= lines;
        int endrange = startrange + code.Length;
        Tuple newrange = new Tuple(startrange + 1, endrange);
        //Debug.Log(newrange);
        return newrange;
    }

    private int LinesCount(string script, int logrange)
    {
        var lines = script.CountLines();
        return lines;
    }

    private string StripTabs(string text)
    {
        Regex tabs = new Regex(@"[ ]{4,}");
        var newCode = tabs.Replace(text, "");
        return newCode;
    }
}
          

This is the class the stores my info about the breakpoint position, file etc.

Breakpoint System

This is how the initialization of the breakpoints works

The Breakpoint System


public static BreakPointSystem Instance
{
  get
  {
  if (_instance == null)
  {
      _instance = new BreakPointSystem();
  }
  return _instance;
  }
}
          

Initialization with Singleton pattern

The Breakpoint System


public void ApplyBreakPoints(BreakPointTemplate template)
{
    xmlDoc.Load(WorkspaceFile);
    XmlNamespaceManager nsmgr = new XmlNamespaceManager(xmlDoc.NameTable);
    nsmgr.AddNamespace("default", xmlDoc.DocumentElement.NamespaceURI);

    XmlNodeList breakpointSections = xmlDoc.SelectNodes("//default:component[@name='XDebuggerManager']/breakpoint-manager/breakpoints", nsmgr);
    if (breakpointSections.Count == 0)
    {
        MakeXDebugger(nsmgr, xmlDoc);
    }

    breakpointSections = xmlDoc.SelectNodes("//default:component[@name='XDebuggerManager']/breakpoint-manager/breakpoints", nsmgr);
    startNode = breakpointSections[0];

    for (int i = 0; i < template._breakpoints.Count; i++)
    {
        CreateXMLBreakPoint(startNode, xmlDoc, template._breakpoints[i]);
    }
    xmlDoc.Save(WorkspaceFile);
}
          

Loading and editing the config file

Applying Breakpoints

The function to generate the XML code

Apply Breakpoints


// url element
var url = doc.CreateElement("url");
url.InnerText = MakeURL(breaker.path);
lineBreakpoint.AppendChild(url);

// line element
var line = doc.CreateElement("line");
line.InnerText = breaker.lineNumber.ToString();
lineBreakpoint.AppendChild(line);

// properties element
var properties = CreateXmlElement(doc, "properties", new Dictionary
{
    {"documentPath", MakeFullPath(breaker.file)}, 
    {"initialLine", breaker.lineNumber.ToString()}, 
    {"containingFunctionPresentation", $"Method '{breaker.method}'"}
});
lineBreakpoint.AppendChild(properties);
          

I analyzed the breakpoint config formatting of the rider ide and made a function that copies the exact format and adds my own info to it

Suggested Projects

Crow Engine

A shader engine inspired by Shadertoy, built to create and explore graphical effects.

C++ Icon Clion Icon Vulkan Icon
Project Image

Vertical Slice

A group school project to remake a proffesional game

C# Icon Visual Studio Icon Unity Icon Blender Icon
Project Image